var initForm = function(){
	$('#_form_default').form({
		url :'sys/LoanExt/addOrUpdateExt',
		onBeforeLoad : function(param){
			$.messager.progress();
		},
		onLoadSuccess : function(data) {
			//加载选中
			if(_is_not_empty(_param_id)){
				//_set_select_selected(data);
				set_disabled();
				}
			$.messager.progress("close");
		},
		onLoadError : function(data) {
			//加载完成之后才构建
			$.messager.progress("close");
			$.messager.alert('提示', "加载内容失败,请重新刷新页面/联系管理员", "error");
		},
		onSubmit : function(param) {
			if (!$(this).form("validate")) {
				$.messager.alert('提示', "提交的选项中,有错误内容,请检查", "error");
				return false;
			}
			$.messager.progress();
		},
		success : function(data) {	
			$.messager.progress("close");
			if(_is_empty(data)){
				$.messager.alert('提示', "未知异常", "error");
				return false;
			}
			var jd = eval('(' + data + ')');
			if(!!!jd){
				$.messager.alert('提示', "未知异常", "error");
				return false;
			}
			if(jd.state!=200){
				$.messager.alert('提示', jd.message, "error");
				return false;
			}
			//获取返回的loan对象
			var rtnLoan = jd.data;
			//如果是新增 设值父页面_client_id和_client_user和add_param_id
			if(_is_not_empty(rtnLoan) && _is_empty(_param_id)){
				    parent._condition_tab1 = true;
					if(_is_not_empty(rtnLoan.clientId)){
						parent._client_id = rtnLoan.clientId;
					}
					if(_is_not_empty(rtnLoan.id)){
						$('#myId').attr('value',rtnLoan.id);
						parent.add_param_id = rtnLoan.id;
					}
					if(_is_empty(parent._client_user['clientIdCard']) && _is_not_empty(rtnLoan.clientCardId)){
						parent._client_user['clientIdCard'] = rtnLoan.clientCardId;
					}
					
					if(_is_empty(parent._client_user['clientName']) && _is_not_empty(rtnLoan.loanBorrower)){
						parent._client_user['clientName'] = rtnLoan.loanBorrower;
					}
			}
			//提交成功以后让身份证和用户名不可编辑
			set_disabled();
			_deal_result_dailog({'tip_title':'提示信息','tip_content':'操作成功!'},function(){
				parent._set_tab1_success(true);
				});
			 _set_result_open();
		}
	});
};


var initAutoComplete = function(){

	$('#loanSourceName').extraAutoComplete({
		// url:'<%=basePath %>sys/SysUser/list',
		 afterSelectedHandler: function(data){//选择数据之后的回调函数
			  $('#loanSourceMan').val(data.id);
	        }
	});
	

};
var set_disabled = function(user){
	if(_is_not_empty(user)){
		if(_is_not_empty(user.clientName)){
			//$('#loanBorrower').attr('value',user.clientName);
			$('#loanBorrower').val(user.clientName);
		}
		if(_is_not_empty(user.clientIdCard)){
			//$('#clientCardId').attr('value',user.clientIdCard);
			$('#clientCardId').val(user.clientIdCard);
		}
	}
	//$('#loanBorrower').removeAttr('data-options');
	//$('#clientCardId').removeAttr('data-options');
	$('#loanBorrower').attr('readonly','readonly');
	$('#clientCardId').attr('readonly','readonly');
};

var _to_valid_cardid = function(){
	
};

var init_select = function(){
	
	$('#loanSource').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Loan_Source_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	//	source:'server',
		//requestData:{dataBaseCode:'Loan_Source_Code'}
	});
	
	$('#loanType').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Loan_Type_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	$('#loanProduct').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Loan_Product_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	$('#loanNatureBusiness').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Loan_Nature_Business_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	$('#loanNatureClilent').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Loan_Nature_Clilent_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	$('#loanNatureFund').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Loan_Nature_Clilent_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	$('#loanPurpose').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Loan_Purpose_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	$('#loanRepayType').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Loan_Repay_Type_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	//
	$('#loanCapitalRound').mSelect({
		myClass:'easyui-validatebox',
		width:90,
		baseCode:'Loan_Capital_Round_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	$('#loanInterestRound').mSelect({
		myClass:'easyui-validatebox',
		width:90,
		baseCode:'Loan_Interest_Round_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	$('#loanInterestType').mSelect({
		myClass:'easyui-validatebox',
		width:90,
		baseCode:'Loan_Interest_Type_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	$('#loanObject').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Loan_Object_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	$('#loanObject').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Loan_Object_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	$('#webId').mSelect({
		myClass:'easyui-validatebox',
		width:308,
		baseCode:'Loan_Web_Id_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	$('#loanKnowStatus').mSelect({
		myClass:'easyui-validatebox',
		width:60,
		baseCode:'Loan_Know_Status_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	
};

$(function(){
	initForm();
	//加载下拉框
	init_select();
	initAutoComplete();
	if(_is_not_empty(_param_id)){
		//编辑 我们不用管
		$("#_form_default").form('load', 'sys/Loan/findByPk?pks=' + _param_id);
		//set_disabled();
	}
	$('input[name="confirm_button"]').click(function(){
		$('#_form_default').submit();
	});
	
});
